{% extends "auth-menu.html" %}
{% load tag %}
{% block head %}
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=krejNXU0gOAVoRnoGTDczzDrvryBXnmM"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script>
    <style type="text/css">
{#		ul,li{list-style: none;margin:0;padding:0;float:left;}#}
		html{height:100%}
		body{height:100%;margin:0px;padding:0px;font-family:"微软雅黑";}
		#container{height:800px;width:100%;}
		#r-result{width:100%;}
    </style>

{#  没有需要加载的文件#}
 {% endblock %}

{% block display1 %}
    "display: block"
{% endblock %}

{% block active1 %}
    'active'
{% endblock %}

{% block active_sub_source_hot %}
    'active'
{% endblock %}

{% block main %}

   <div class='span12'>
            <h4 class='pull-left'>
                <form accept-charset="utf-8" class="navbar-search pull-left hidden-phone" method="get" />
                    <div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
                              数据源：
                                        <select id='inputSelect' name="source" style="width:100px;" >
                                        {% for i in source_list %}
                                            <option {{ i.select }}/>{{ i.source | code_gbk }}
                                        {% endfor %}
                                        </select>
                <button class="btn btn-link icon-search " name="button" type="submit"></button>
{#            </h4>#}
{##}
{#            <h4 div class='pull-left'>#}
               &nbsp &nbsp &nbsp城市:{{ cityname }} &nbsp 时间:{{ time_str }}&nbsp  TIMEID:{{ timeid }} &nbsp 车辆数:{{ cars }} &nbsp GPS量:{{ data_total }} &nbsp 平均上传间隔:{{ interval}}秒

            </h4>
    </div>

  	<div id="r-result">
		<input type="button"  onclick="openHeatmap();" value="显示热力图"/><input type="button"  onclick="closeHeatmap();" value="关闭热力图"/>
	</div>
	<div id="container"></div>
{% endblock %}

{% block script %}
{#    <script type="text/javascript" src="http://developer.baidu.com/map/custom/stylelist.js"></script>#}
{% endblock %}

{% block html %}
    <script type="text/javascript">
    var map = new BMap.Map("container");          // 创建地图实例

{#    {% if cars %}#}
{#        map.centerAndZoom( "{{ cityname | safe }}",12);#}
{#    {% else %}#}
    {% if chengji == 1 %}
         map.centerAndZoom(new BMap.Point({{ coordinate }}), 6);
    {% else %}
        map.centerAndZoom(new BMap.Point({{ coordinate }}), 12);     // 初始化地图,设置中心点坐标和地图级别
    {% endif %}
{#    {% endif %}#}

    map.enableScrollWheelZoom(); // 允许滚轮缩放

    var points ={{ list | safe  }};
{#var points =[ {"lng":116.42076,"lat":39.915252,"count":100}];#}
    if(!isSupportCanvas()){
    	alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~')
    }
	//详细的参数,可以查看heatmap.js的文档 https://github.com/pa7/heatmap.js/blob/master/README.md
	//参数说明如下:
	/* visible 热力图是否显示,默认为true
     * opacity 热力的透明度,0-1 范围
     * radius 势力图的每个点的半径大小
     * gradient  {JSON} 热力图的渐变区间 . gradient如下所示
     *	{
			.2:'rgb(0, 255, 255)',
			.5:'rgb(0, 110, 255)',
			.8:'rgb(100, 0, 255)'
		}
		其中 key 表示插值的位置, 0~1.'interval':300/(data_total/cars)
		    value 为颜色值.
     */
	heatmapOverlay = new BMapLib.HeatmapOverlay({"radius":30,'opacity':0});
	map.addOverlay(heatmapOverlay);

	heatmapOverlay.setDataSet({data:points,max:100});
	//是否显示热力图
    function openHeatmap(){
        heatmapOverlay.show();
    }
	function closeHeatmap(){
        heatmapOverlay.hide();
    }
	closeHeatmap();
    function setGradient(){
     	/*格式如下所示:
		{
	  		0:'rgb(102, 255, 0)',
	 	 	.5:'rgb(255, 170, 0)',
		  	1:'rgb(255, 0, 0)'
		}*/
     	var gradient = {};
     	var colors = document.querySelectorAll("input[type='color']");
     	colors = [].slice.call(colors,0);
     	colors.forEach(function(ele){
			gradient[ele.getAttribute("data-key")] = ele.value;
     	});
        heatmapOverlay.setOptions({"gradient":gradient});
    }
	//判断浏览区是否支持canvas
    function isSupportCanvas(){
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }
</script>
{% endblock %}
